/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package android.utils;

/**
 *
 * @author Tew
 */
import android.components.LeftGlove;
import android.components.MoveButton;
import android.components.RightGlove;
import android.content.Context;
import android.goalkeeper.R;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.opengl.GLSurfaceView;

public class GameController extends GLSurfaceView {

    private LeftGlove mGloveLeftInstance;
    private RightGlove mGloveRightInstance;
    private MoveButton mMoveButtonInstance;
    private GameControllerTouchListener mTouchListener;

    public GameController(Context context, OnTouchListener listener) {
        super(context);
        mTouchListener = (GameControllerTouchListener) listener;
        //Add SurfaceCallback
        mGloveLeftInstance = new LeftGlove(BitmapFactory.decodeResource(getResources(), R.drawable.glove_l), mTouchListener.X, mTouchListener.Y);
        mGloveRightInstance = new RightGlove(BitmapFactory.decodeResource(getResources(), R.drawable.glove_r), mGloveLeftInstance.getX() + 50, mGloveLeftInstance.getY());
        mMoveButtonInstance = new MoveButton(BitmapFactory.decodeResource(getResources(), R.drawable.movebutton), mGloveLeftInstance.getX() + 25, mGloveLeftInstance.getY() + 30);
        setFocusable(true);
    }

    public void render(Canvas canvas) {
        //re implement it via opengl
        canvas.drawColor(Color.BLACK);
        mGloveLeftInstance.draw(canvas);
        mGloveRightInstance.draw(canvas);
        mMoveButtonInstance.draw(canvas);
        
    }

    public void update() {
        gloveUpdate(mTouchListener.X, mTouchListener.Y);
    }
    
    public void gloveUpdate(float x,float y){
        mGloveLeftInstance.update(x-25,y-30); 
        mGloveRightInstance.update(x+25,y-30); 
        mMoveButtonInstance.update(x,y); 
    }
}
